package com.eveinfo.api.accessors;

import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;

import com.eveinfo.EveInfo;
import com.eveinfo.api.ApiAuthorization;
import com.eveinfo.api.ApiException;
import com.eveinfo.api.NoCacheFoundExecption;
import com.eveinfo.api.character.sheet.ApiSheet;
import com.eveinfo.api.character.sheet.SheetParser;
import com.eveinfo.tools.EveInfoPreferences;
import com.eveinfo.tools.Tools;

public class CharacterSheet {
	
	private ApiSheet sheet;

	public CharacterSheet(int userID, long characterID, String apiKey)
			throws IOException, SAXException, ParserConfigurationException, ApiException, NoCacheFoundExecption {
		SheetParser parser = SheetParser.getInstance();
		final EveInfoPreferences preferences = EveInfo.getPreferences();
		if (preferences.isCacheOnly()) {
			parser.setCacheOnly(true);
			preferences.setEnableCache(true);
		} else {
			parser.setCacheOnly(false);
		}
		if (preferences.isEnableCache()) {
			Tools.setCacheEnable(parser);
		} else {
			Tools.setCacheDisable(parser);
		}
		sheet = parser.getCharacterSheet(new ApiAuthorization(userID,
				characterID, apiKey));
	}

	public ApiSheet getApiSheet() {
		return sheet;
	}
	
}